<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

return [
    'id' => 'app-api',
    'basePath' => dirname(__DIR__),
    'language' => 'zh-CN',
    'bootstrap' => ['log'],
    'controllerNamespace' => 'api\controllers',
    'modules' => [
        'v1' => [
            'class' => 'api\modules\v1\Module',
        ],
        'mp' => [
            'class' => 'api\modules\mp\Module',
        ],
    ],
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-api',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ],
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-cooldive', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the api
            'name' => '_identity-cooldive-s',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'logFile' => '/dive/www/applogs/cooldive/runtime_' . date('Ymd') . '.log',
                    'levels' => ['error', 'warning', 'info'],
                    'logVars' => [],
                    'prefix' => function($message){
                        if (Yii::$app === null) {
                            return '';
                        }
                        $request = Yii::$app->getRequest();
                        $ip = $request instanceof \yii\web\Request ? $request->getUserIP() : '-';
                        /* @var $user \yii\web\User */
                        $user = Yii::$app->has('user', true) ? Yii::$app->get('user') : null;
                        if ($user && ($identity = $user->getIdentity(false))) {
                            $userID = $identity->getId();
                        } else {
                            $userID = '-';
                        }
                        return "[$ip][$userID]";
                    },
                    //'except' => YII_ENV_PROD ? ['yii*'] : [],
                    'exportInterval' => 100,
                    'maxFileSize' => 2048000,
                    'maxLogFiles' => 365,
                    'rotateByCopy' => False,
                    'fileMode' => 0777,
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'cache' => [
            'class' => 'yii\redis\Cache',
        ],
    ],
    'params' => $params,
];
